(
    function (factory) {
      if (typeof define === "function" && define.amd) {

        // AMD. Register as an anonymous module.
        define(["jquery", "./version"], factory);
      } else {

        // Browser globals
        factory(jQuery);
      }
    }
    (
        function($){

            var watchClass = function () {
                function init(){
                    var mycharts_real = echarts.init(document.getElementById("main"));
                    var mycharts_dis = echarts.init(document.getElementById("sys-distribution"));

                    var mycharts_lighting = echarts.init(document.getElementById('sys-lighting'));
                    var mycharts_air = echarts.init(document.getElementById('sys-air'));
                    var mycharts_elevator = echarts.init(document.getElementById('sys-elevator'));           


                    //实时监测
                    Highcharts.setOptions({
                        global : {
                            useUTC : false
                        }
                    });
                     // Create the chart
                     $('#main').highcharts('StockChart', {
                         chart : {
                             type:'line',
                             events : {
                                 load : function () {
                                     // set up the updating of the chart each second
                                     var series_light = this.series[0];
                                     var series_air = this.series[1];
                                     var series_elevator = this.series[2];
                
                                     setInterval(function () {
                                         var x = (new Date()).getTime(); // current time
                                             y0 = Math.round(Math.random() * 25 + 50);
                                             y1 = Math.round(Math.random() * 25 + 50);
                                             y2 = Math.round(Math.random() * 25 + 30);
                                             series_light.addPoint([x, y0], true, true);
                                             series_air.addPoint([x, y1], true, true);
                                             series_elevator.addPoint([x, y2], true, true);
                                            //  console.log(series.name)
                                     }, 1000);
                                 }
                             }
                         },
                         rangeSelector: {
                             buttons: [{
                                 count: 60,
                                 type: 'minute',
                                 text: '1h'
                             }, {
                                 count: 300,
                                 type: 'minute',
                                 text: '5h'
                             }, {
                                 type: 'all',
                                 text: '1 Day'
                             }],
                             inputEnabled: false,
                             selected: 0
                         },
                         title : {
                             text : '耗电实时监测'
                         },
                         yAxis:{
                             title: {
                                 text: '耗电量 (kWh)'
                             },
                         },
                         tooltip: {
                             split: true,
                             valueSuffix: ' kWh'
                         },
                         exporting: {
                             enabled: false
                         },
                         series : [{
                             name : '照明系统',
                             data : (function () {
                                 // generate an array of random data
                                 var data = [], time = (new Date()).getTime(), i;
                                 for (i = -86400; i <= 0; i += 1) {
                                     data.push([
                                         time + i * 1000,
                                         Math.round(Math.random() * 25 + 50)
                                     ]);
                                 }
                                 return data;
                             }())
                         },
                         {
                            name : '空调系统',
                            data : (function () {
                                // generate an array of random data
                                var data = [], time = (new Date()).getTime(), i;
                                for (i = -86400; i <= 0; i += 1) {
                                    data.push([
                                        time + i * 1000,
                                        Math.round(Math.random() * 25 + 50)
                                    ]);
                                }
                                return data;
                            }()),
                            color: '#90ED7D'
                        },
                        {
                            name : '电梯系统',
                            data : (function () {
                                // generate an array of random data
                                var data = [], time = (new Date()).getTime(), i;
                                for (i = -86400; i <= 0; i += 1) {
                                    data.push([
                                        time + i * 1000,
                                        Math.round(Math.random() * 25 + 30)
                                    ]);
                                }
                                return data;
                            }()),
                            color: '#F7A35C' 
                        }
                    ]
                     });



                    //系统分布
                    option_dis = {
                        title : {
                            text: '今日用电总量各系统分布',
                        },
                        tooltip : {
                            trigger: 'item',
                            formatter: "{a} <br/>{b} : {c} ({d}%)"
                        },
                        legend: {
                            orient: 'horizontal',
                            left: 'right',
                            data: ['照明系统','空调系统','电梯系统']
                        },
                        series : [
                            {
                                name: '耗电分布',
                                type: 'pie',
                                radius : '57%',
                                center: ['60%', '64%'],
                                data:[
                                    {value:335, name:'照明系统'},
                                    {value:310, name:'空调系统'},
                                    {value:204, name:'电梯系统'},
                                ],
                                itemStyle: {
                                    emphasis: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    mycharts_dis.setOption(option_dis);

                    //区域分布
                    distribute_lighting = {
                        title : {
                            text: '照明系统今日用电总量区域分布',
                        },
                        tooltip : {
                            trigger: 'item',
                            formatter: "{a} <br/>{b} : {c} ({d}%)"
                        },
                        legend: {
                            orient: 'horizontal',
                            left: '60%',
                            data: ['A','B','C','D']
                        },
                        series : [
                        {
                            name: '区域耗电分布',
                            type: 'pie',
                            radius : ['35%','60%'],
                            innerRadius:'30%',
                            center: ['50%', '60%'],
                            data:[
                                {value:335, name:'A'},
                                {value:310, name:'B'},
                                {value:234, name:'C'},
                                {value:252, name:'D'},
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                        ]
                    };

                    distribute_air = {
                        title : {
                            text: '空调系统今日用电总量区域分布',
                        },
                        tooltip : {
                            trigger: 'item',
                            formatter: "{a} <br/>{b} : {c} ({d}%)"
                        },
                        legend: {
                            orient: 'horizontal',
                            left: '60%',
                            data: ['A','B','C','D']
                        },
                        series : [
                        {
                            name: '区域耗电分布',
                            type: 'pie',
                            radius : ['35%','60%'],
                            innerRadius:'30%',
                            center: ['50%', '60%'],
                            data:[
                                {value:325, name:'A'},
                                {value:410, name:'B'},
                                {value:534, name:'C'},
                                {value:492, name:'D'},
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                        ]
                    };

                    distribute_elevator = {
                        title : {
                            text: '空调系统今日用电总量区域分布',
                        },
                        tooltip : {
                            trigger: 'item',
                            formatter: "{a} <br/>{b} : {c} ({d}%)"
                        },
                        legend: {
                            orient: 'horizontal',
                            left: '60%',
                            data: ['A','B','C','D']
                        },
                        series : [
                        {
                            name: '区域耗电分布',
                            type: 'pie',
                            radius : ['35%','60%'],
                            innerRadius:'30%',
                            center: ['50%', '60%'],
                            data:[
                                {value:325, name:'A'},
                                {value:510, name:'B'},
                                {value:534, name:'C'},
                                {value:492, name:'D'},
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                        ]
                    };
                    
                    mycharts_lighting.setOption(distribute_lighting);
                    mycharts_air.setOption(distribute_air);
                    mycharts_elevator.setOption(distribute_elevator);
                    
                    //选择联动


                }
                this.init = init;
                
            }
            var watchInit=function () {
                var watch = new watchClass()
                watch.init()
            }
            $(watchInit)

        }
    )
)


// //选择联动
// var regions;
// $.get('mockdata/distributionDataMonitor.json').done(
//     function (data) {
//       regions = data;
//       for(i=0;i<data.regions.length;i++){
//           $("#area").append("<option>"+data.regions[i].regionName+"</option>")
//       }
//     }
//   );

// function removeBuilding() {
//     $("#building")[0].options.length=0;
//     $("#building").append("<option>"+"----"+"</option>");
// }
// function removeFloor() {
//     $("#floor")[0].options.length=0;
//     $("#floor").append("<option>"+"----"+"</option>");
// }
// function removeRoom() {
//     $("#room")[0].options.length=0;
//     $("#room").append("<option>"+"----"+"</option>");
// }
// function onAreaSelect(){
//     removeBuilding();
//     removeFloor();
//     removeRoom();
//     var area = $("#area").val();
//     for(var i=0;i<regions.regions.length;i++){
//         if(area === regions.regions[i].regionName){
//             for(var j=0;j<regions.regions[i].buildings.length;j++){
//                 $("#building").append("<option>"+regions.regions[i].buildings[j].buildingName+"</option>")
//             }
//         }
//     }
// }
// function onBuildingSelect(){
//     removeFloor();
//     removeRoom();
//     var building = $("#building").val();
//     for(var i=0;i<regions.regions.length;i++){
//         for(j=0;j<regions.regions[i].buildings.length;j++){
//             if(building === regions.regions[i].buildings[j].buildingName){
//                 for(var m=0;m<regions.regions[i].buildings[j].floors.length;m++){
//                     $("#floor").append("<option>"+regions.regions[i].buildings[j].floors[m].floorName+"</option>")
//                 }
//             }
//         }
//     }
// }
// function onFloorSelect(){
//     removeRoom();
//     var floor = $("#floor").val();
//     for(var i=0;i<regions.regions.length;i++){
//         for(j=0;j<regions.regions[i].buildings.length;j++){
//             for(m=0;m<regions.regions[i].buildings[j].floors.length;m++){
//                 if(floor === regions.regions[i].buildings[j].floors[m].floorName){
//                     for( n=0;n<regions.regions[i].buildings[j].floors[m].Rooms.length;n++){
//                         $("#room").append("<option>"+regions.regions[i].buildings[j].floors[m].Rooms[n].roomName+"</option>")
//                     }
//                 }
//             }
//         }
//     }
// }